#include "threadPool.h"

ThreadPool::~ThreadPool()
{
	ThreadVectorType::iterator iter = _threads.begin();
	ThreadVectorType::iterator iter_end = _threads.end();
	for (; iter != iter_end; iter ++)
		delete *iter;
}


int ThreadPool::Start()
{
	if (_Prepare() < 0)
		return -1;

	ASSERT(!_threads.empty());

	ThreadVectorType::iterator iter = _threads.begin();
	ThreadVectorType::iterator iter_end = _threads.end();
	for (; iter != iter_end; iter ++)
		if ((*iter)->Start() < 0)
			return -1;

	return 0;
}


int ThreadPool::Stop()
{
	ThreadVectorType::iterator iter = _threads.begin();
	ThreadVectorType::iterator iter_end = _threads.end();
	for (; iter != iter_end; iter ++)
		(*iter)->Stop();

	_Finish();
	return 0;
}
